<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html; charset=utf-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>平台管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all">
</head>
<body>
<div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list" style="padding: 20px 30px 0 0;">
    <input type="hidden" name="cid" value="${customer.id}">
    <input type="hidden" id="parentid" name="parentid">
    <div class="layui-form-item">
        <label class="layui-form-label">当前推荐人手机号</label>
        <div class="layui-input-inline">
            <input type="text" autocomplete="off" class="layui-input" value="${empty parent ?  '无':parent.phone }" disabled style="cursor: not-allowed !important;">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">当前推荐人姓名</label>
        <div class="layui-input-inline">
            <input type="text" autocomplete="off" class="layui-input" value="${empty parent ?  '无':parent.nickName }" disabled style="cursor: not-allowed !important;">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">新的推荐人手机号</label>
        <div class="layui-input-inline">
            <input type="text" id="phone" name="phone" autocomplete="off" class="layui-input phone" placeholder="请输入手机号码" value="">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">新的推荐人姓名</label>
        <div class="layui-input-inline">
            <input type="text" id="newParentName" autocomplete="off" class="layui-input" value="" disabled style="cursor: not-allowed !important;">
        </div>
    </div>  
	<div class="layui-form-item layui-hide">
	  <input type="button" lay-submit lay-filter="layuiadmin-app-form-submit" id="layuiadmin-app-form-submit" value="确认添加">
	  <input type="button" lay-submit lay-filter="layuiadmin-app-form-edit" id="layuiadmin-app-form-edit" value="确认编辑">
	</div>  
</div>

<script src="/layuiadmin/layui/layui.js"></script>  
<script>
    layui.config({
        //静态资源所在路径
        base: '/layuiadmin/'
    }).extend({
        //主入口模块
        index: 'lib/index'
    }).use(['index', 'form'], function(){
        var $ = layui.$
        ,form = layui.form;
        
        //监听提交
        form.on('submit(layuiadmin-app-form-submit)', function(data){
          var field = data.field; //获取提交的字段
          var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引  
          //提交 Ajax 成功后，关闭当前弹层并重载表格
          //$.ajax({});
          //新增
    	  $.ajax({
      		url:"/customer/updateParent",
      		dataType:"json",
      		data:field,
    		type : "post",
    		success : function(res) {
    			if (res.status) {
    			      parent.layui.table.reload('table'); //重载表格
    			      parent.layer.close(index); //再执行关闭 
    			}
    			layer.msg(res.desc);
    		}
    	  });
        });
        
        $(".phone").on("change",function(){
      	  $.ajax({
        		url:"/customer/getCustomer",
        		dataType:"json",
        		data:{
        			phone:$("#phone").val()
        		},
      		type : "post",
      		success : function(res) {
      			if (res.status) {
      				$("#newParentName").val(res.data.nickName);
      				$("#parentid").val(res.data.id);
      			}else{
          			layer.msg(res.desc);
      			}
      		}
      	  });
        });
    });
</script>
</body>
</html>